package priv.mill.httpclient;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;

public interface HttpAnnotationHandler {

	void resolve(Annotation annotation, Object[] args, int i) throws Exception;

	default void baseResove(Object[] args, int i, String url, String[] argNames, String[] argValues)
			throws Exception, IOException {
		if(argNames.length>0) {
			Map<String,Object> map = new HashMap<>();
			if(argValues.length==argNames.length) { //如果注解中提供了相应的值
				for (int j = 0; j < argNames.length; j++) {
					map.put(argNames[j], argValues[j]);
				}
			}else { //否则就去参数中找Map或者实体类拿
				Map<String, Object> array2Map = getArgMapers(args);//reflectUtil.array2Map(args);
				for (int j = 0; j < argNames.length; j++) {
					Object object = array2Map.get(argNames[j]);
					if(object!=null)
					map.put(argNames[j], object);
				}
			}
			String doGet = query(url,map);//httpUtil.doGet(value,map);
			args[i]=doGet;
		}else {
			String doGet = query(url);//httpUtil.doGet(value);
			args[i]=doGet;
			
		}
	}

	String query(String url) throws Exception;

	String query(String url, Map<String, Object> map) throws Exception;

	Map<String, Object> getArgMapers(Object[] args) throws Exception;
}
